home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 28
/
Aminet 28 (1998)(GTI - Schatztruhe)[!][Dec 1998].iso
/
Aminet
/
hard
/
drivr
/
BetaScan_1.12.lha
/
BetaScan
/
ScannerDev
/
ScanMakerE3.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-10-04
|
18KB
|
676 lines
//*********************************************************************
//
// ScanmakerE3 Scanner device
//
// version 98.07.18
//
//*********************************************************************
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#include <string.h>
#include <math.h>
#include <exec/types.h>
#include <proto/exec.h>
#include <proto/dos.h>
#include "scsi.h"
#include "Scanner.h"
char DevName[] = "ScanmakerE3.device";
char DevIdString[] = "ScanmakerE3";
typedef unsigned char ScanCmd[6];
// Scanner specifik defines
#define MAX_BASE_RES 300
#define MAX_EXT_RES 300
// scanning modes
#define SCANMODE_HALFTONE 0
#define SCANMODE_BW 1
#define SCANMODE_GREY 2
#define SCANMODE_COLOR 3
#define SCANBUFSIZE 32000
#define MAX_BUSY_RETRY 5
static UBYTE* scanBuffer = NULL;
// Stored scanning parameters
//
static double x0; /* Scanning frame in mm */
static double y0;
static double x1;
static double y1;
static UBYTE resolutionCode; /* Resolution in % of max resolution */
static UBYTE resolutionFlag; /* Further resolution information */
static WORD brightness[3]; /* Brightness for red, green and blue */
static WORD contrast; /* Contrast */
static WORD shadow; /* shadow adjust 0..1023 (default 0) */
static WORD highlight; /* highlight adjust 0..1023 (def. 0) */
static WORD midtone; /* midtone adjust 0..1023 (def. 512) */
static WORD halftonePattern;/* halftonePattern 0..255 (def. 0) */
static WORD exposureTime; /* Exposure time */
static double gamma; /* gamma value */
static WORD scanMode; /* see above */
static BOOL extendedRes; /* extended resolution */
static BOOL parametersSet; /* parameters are set */
// Actual scanning values
//
static UWORD imageWidth;
static UWORD imageHeight;
static UWORD bytesPerLine;
static UWORD xResolution;
static UWORD yResolution;
// Parameters used during scanning
//
static BOOL scanning; /* Scanner is scanning */
static int lineWidth; /* Length of one scan line including color informat. */
static int scanLines; /* Total number of lines to read from scanner */
static int numPlanes; /* 3 for rgb24, otherwise 1 */
static int bufferLen; /* Length of scanBuffer in number of lines */
static int linesRead; /* Lines already read from scanner */
static int linesInBuf; /* Number of lines read from scanner in scanBuffer */
static int currentLine; /* Next line from scanBuf to return to user */
static int nextPlane; /* next plane number to return to readScanLine */
//
// Make color correction table brightness and contrast
//
UBYTE corrTab[256];
void makeCorrTab(int bright,int contrast)
{
int i,b,c;
UBYTE* tab;
tab = corrTab;
bright = (bright*255)/100;
c = 100+contrast;
for( i = 0 ; i < 256 ; i++ )
{
b = ((i+bright)*c-50*contrast)/100;
*(tab++) = b>255?255:(b<0?0:(UBYTE)b);
}
}
/*------------------------------------------------------------------------*/
static void scannerReady(BYTE *error)
{
if( *error == 0 )
{
ScanCmd TEST_UNIT_READY = { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
int retry = 0;
while( sendCommand(TEST_UNIT_READY, 6, NULL, 0, NULL, 0) )
{
retry++;
if (retry == 5)
{
*error = SCAN_ERR_READY;
return;
}
Delay(3*50);
}
}
}
/*------------------------------------------------------------------------*/
static void setScanningFrame(BYTE *error)
{
if( *error == 0 )
{
ScanCmd SCANNING_FRAME = { 0x04, 0x00, 0x00, 0x00, 0x09, 0x00 };
UBYTE frame_data[9];
int xf0,yf0,xf1,yf1;
int dpi;
frame_data[0] = 0x00;
if( scanMode == SCANMODE_HALFTONE )
frame_data[0] |= 0x01;
// Unit is pixel
//
frame_data[0] |= 0x08;
dpi = MAX_BASE_RES;
xf0 = (int)((double)(x0*dpi)/25.4);
yf0 = (int)((double)(y0*dpi)/25.4);
xf1 = (int)((double)(x1*dpi)/25.4);
yf1 = (int)((double)(y1*dpi)/25.4);
frame_data[1] = (UBYTE)(xf0 & 0xff);
frame_data[2] = (UBYTE)((xf0 & 0xff00) >> 8);
frame_data[3] = (UBYTE)(yf0 & 0xff);
frame_data[4] = (UBYTE)((yf0 & 0xff00) >> 8);
frame_data[5] = (UBYTE)(xf1 & 0xff);
frame_data[6] = (UBYTE)((xf1 & 0xff00) >> 8);
frame_data[7] = (UBYTE)(yf1 & 0xff);
frame_data[8] = (UBYTE)((yf1 & 0xff00) >> 8);
*error = sendCommand(SCANNING_FRAME, 6, frame_data, 9, NULL, 0);
}
}
/*------------------------------------------------------------------------*/
static void selectMode(BYTE *error)
{
if( *error == 0 )
{
ScanCmd MODE_SELECT = { 0x15, 0x00, 0x00, 0x00, 0x0B, 0x00 };
UBYTE mode_data[11];
mode_data[0] = 0x81;
// Set resolution
mode_data[0] |= 0x02;
mode_data[1] = resolutionCode;
mode_data[2] = (exposureTime/3)+7;
mode_data[3] = (contrast+49)/7;
mode_data[4] = halftonePattern;
mode_data[5] = 0x01;
mode_data[6] = shadow;
mode_data[7] = highlight;
mode_data[8] = 0x6C;
mode_data[9] = 0x00;
mode_data[10] = midtone;
*error = sendCommand(MODE_SELECT, 6, mode_data, 11, NULL, 0);
}
}
/*------------------------------------------------------------------------*/
void mode_sense_1(BYTE *error)
{
if( *error == 0 )
{
ScanCmd MODE_SELECT_1 = { 0x16, 0x00, 0x00, 0x00, 0x0a, 0x00 };
unsigned char mode_data[10] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
mode_data[1] = (UBYTE)(brightness[0]);
*error = sendCommand(MODE_SELECT_1, 6, mode_data, 10, NULL, 0);
}
if( *error == 0 )
{
ScanCmd MODE_SENSE_1 = { 0x19, 0x00, 0x00, 0x00, 0x1e, 0x00 };
unsigned char mode_data[30] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
mode_data[1] = (UBYTE)(brightness[0]);
mode_data[2] = (UBYTE)(brightness[1]);
mode_data[3] = (UBYTE)(brightness[2]);
*error = sendCommand(MODE_SENSE_1, 6, mode_data, 30, NULL, 0);
}
}
/*------------------------------------------------------------------------*/
/* int lut_download (char filter, char *gtable, int gt_entries) */
/* Issue the LOOK-UP-TABLE DOWNLOAD command to the scanner to download */
/* the gamma table pointed to by <gtable>. <filter> determines the color */
/* to which the table applies (RED, GREEN, BLUE, or CLEAR; values other */
/* than CLEAR may only be specified for one-pass color scanners). The */
/* number of entries is determined by <entries> (256, 1024, 4096 or */
/* 65536). The entry width is automatically assumed to be one byte if the */
/* number of entries is 256 and two bytes otherwise. */
/*------------------------------------------------------------------------*/
void gammaTable(double g, BYTE *error)
{
if( *error == 0 )
{
UBYTE LUT_DOWNLOAD[10] = {0x55,0x00,0x27,0x00,0x00,0x00,0x00,0x00,0x00,0x00 };
UBYTE gTable[256];
int i;
LUT_DOWNLOAD[7] = (UBYTE)((256 & 0xff00) >> 8);
LUT_DOWNLOAD[8] = (UBYTE)(256 & 0xff);
if( (g <= 0.0) || (g == 1.0) )
{
for( i = 0 ; i < 256 ; i++ )
gTable[i] = (UBYTE)i;
}
else
{
for( i = 0 ; i < 256 ; i++ )
gTable[i] = (UBYTE)(256.0*pow(((double)i)/256.0,1/g));
}
*error = sendCommand(LUT_DOWNLOAD,10,gTable,256,NULL,0);
}
}
/*------------------------------------------------------------------------*/
static void accessory(BYTE *error)
{
if( *error == 0 )
{
ScanCmd ACCESSORY = { 0x10, 0x00, 0x00, 0x00, 0x9A, 0x00 };
*error = sendCommand(ACCESSORY, 6, NULL, 0, NULL, 0);
}
}
/*------------------------------------------------------------------------*/
static void startScan(BYTE *error)
{
if( *error == 0 )
{
ScanCmd START_SCAN = { 0x1b, 0x00, 0x00, 0x00, 0x01, 0x00 };
switch( scanMode )
{